<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
namespace app\api\validate\wddj\usert;

use think\Validate;

class EmergencyContact extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'name'=>'require|checkName',
        'mobile'=>'require|checkMobile',
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'name.require'=>'请输入姓名',
        'mobile.require'=>'请输入手机号码',
    ];

    protected function checkName($value,$rule,$data)
    {
        $emergencyContactObj = (new \app\api\model\wddj\user\EmergencyContact())
            ->where('wechat_id',$data['wechat_id'])
            ->where('name',$value)
            ->find();
        if ($emergencyContactObj) {
            return '姓名已存在';
        }
        return true;
    }

    protected function checkMobile($value,$rule,$data)
    {
        if (!$value || !\think\Validate::regex($value, "^1\d{10}$")) {
            return '手机号格式不正确';
        }
        $emergencyContactObj = (new \app\api\model\wddj\user\EmergencyContact())
            ->where('wechat_id',$data['wechat_id'])
            ->where('mobile',$value)
            ->find();
        if ($emergencyContactObj) {
            return '手机号码已存在';
        }
        return true;
    }




    
}
